from abstract_node.extended_event import ExtendedSensorEvent

class AbstractInputLayer():
    
    def __init__(self, inputInterface, mapping_fct, filtering_fct, trigger_fct=[]):
        self.input_interface=inputInterface
        self.input_event=ExtendedSensorEvent(self.input_interface.properties)
        self.trigger_fct=trigger_fct
        self.mapping_fct=mapping_fct
        self.filtering_fct=filtering_fct
        self.input_interface.set_notification_fcn(self.measurement_received) 
        self.input_events=[]
        
    def measurement_received(self, value, time):
        self.mapping_fct(value, time)
        event_appended=self.filtering_fct()
        if self.trigger_fct!=[] and event_appended==True:
            self.trigger_fct()
        
    def start_measurements(self):
        self.input_interface.start_measurements()
        
    def stop_measurements(self):
        self.input_interface.stop_measurements()
        